import { ref } from 'vue'
import { defineStore } from 'pinia'

export const useUserStore = defineStore('user', () => {
  const user = ref(JSON.parse(localStorage.getItem('admin_user')) || null)
  
  function setUser(userData) {
    user.value = userData
    localStorage.setItem('admin_user', JSON.stringify(userData))
  }
  
  function clearUser() {
    user.value = null
    localStorage.removeItem('admin_user')
  }
  
  return {
    user,
    setUser,
    clearUser
  }
})